#include "HomeFire.h"
#include <random>
#include "SFML\Window\Keyboard.hpp"
#include "SFML\Window\Joystick.hpp"
#include "Objects/Particle.h"

#include <iostream>
using namespace std;

HomeFire::HomeFire(GameState *gameState) : GameObject(gameState)
{

	setLayer(2);

	m_time = 0;

	setColor(1.0f, 0.4f, 0.1f);
	

	m_shader = gameState->getShaderManager().getShader("homeFire");

}


HomeFire::~HomeFire()
{
}


void HomeFire::update(double dt){
	static int direction = 1;
	m_time += dt*direction;

	if(m_time >= 3*3.1416f && direction == 1){
		direction = -1;
	}else if(m_time < 0.0f && direction == -1){
		direction = 1;
	}
}

void HomeFire::draw(){


	sf::Shader::bind(m_shader);

	m_shader->setParameter("time", (float)m_time);

	glColor4fv(m_color);
	glPushMatrix();
	{
		glTranslatef(m_position.x, m_position.y, 0); 
		glScalef(getSize().x, getSize().y, 1);
		glBegin(GL_QUADS);
		{
			glTexCoord2f(0.0f, 1.0f); glVertex3f( -0.5f, -0.5f, -0.2f);
			glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.5f, -0.5f, -0.2f);
			glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.5f, 0.5f, -0.2f);
			glTexCoord2f(0.0f, 0.0f); glVertex3f( -0.5f, 0.5f, -0.2f);
		}
		glEnd();
	}
	glPopMatrix();

	sf::Shader::bind(NULL);
	
}
